package org.nidy.programexercise.ThreadExercise;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadExercise {
    public static void main(String[] args) {

//        Thread t1 = new ThreadDemo();
//        Thread t2 = new ThreadDemo();
//        Thread t3 = new ThreadDemo();
//        RunableDemo r1 = new RunableDemo();
//        RunableDemo r2 = new RunableDemo();
//        RunableDemo r3 = new RunableDemo();
//        Thread t1 = new Thread(r1);
//        Thread t2 = new Thread(r2);
//        Thread t3 = new Thread(r3);
//        t1.setName("Line01");
//        t2.setName("Line02");
//        t3.setName("Line03");
//        t1.start();
//        t2.start();
//        t3.start();
        System.out.println("======================================");
        // 创建 Callable 实例
        Callable<Integer> callable = new CallableDemo();
        // 使用 FutureTask 包装 Callable
        FutureTask<Integer> futureTask = new FutureTask<>(callable);

        // 创建并启动线程
        Thread thread = new Thread(futureTask);
        thread.start();

        try {
            // 获取 Callable 的返回结果
            Integer result = futureTask.get();
            System.out.println("Callable 返回的结果: " + result);
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("======================================");
        //多线程售货
        ThreadSalesTicket t1=new ThreadSalesTicket();
        ThreadSalesTicket t2=new ThreadSalesTicket();
        ThreadSalesTicket t3=new ThreadSalesTicket();
        t1.setName("Line1");
        t2.setName("Line2");
        t3.setName("Line3");
        t1.start();
        t2.start();
        t3.start();
    }
}
